<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop" ref="buttondiv">
          <template>
              <table width="100%">
                  <tr>
                      <td>仪器</td>
                      <td>
                          <rm-ddl-instrument @change="labinstrumentchange" width="200px" v-model="instrId" defaultflag="1" prgno="LIS513" :clearable="false"></rm-ddl-instrument>
                      </td>
                      <td align="right">
                          <el-button icon="el-icon-search" @click="initialList" v-has="'PINQUERY'">查询(F8)</el-button>
                          <el-button icon="el-icon-edit-outline" @click.shift="BtnAdd()" @click="BtnAdd()" v-has="'PADD'">新增(F2)</el-button>
                          <el-button icon="el-icon-delete-solid" @click="BtnDel()" v-has="'PDELETE'">删除(F3)</el-button>
                          <el-button type="primary" icon="el-icon-success" @click="BtnSave()" v-has="'PMODIFY'">保存(F6)</el-button>
                          <el-button icon="el-icon-close" @click="BtnExc">退出(E)</el-button>
                      </td>
                  </tr>
              </table>
          </template>
      </div>
      <div class="pagecenter">
          <rm-layout-right splitcolor="#FFFFFF" movingcolor="#CCFFFF" :splitwidth=5 :fixsize=600 :minfixsize="500" :maxfixsize="500" :canDrag="true">
              <div ref="xTableDiv" style="height: 99%; width: 100%">
                  <vxe-table show-overflow ref="xTable1" height="auto" width="100%" :loading="loading" :select-config="{ reserve: true }" :data.sync="tableData1" border size="mini" :row-class-name="rowClassName" :keyboard-config="keyConfig" :mouse-config="{ selected: true }" @cell-dblclick="openRule" show-header-overflow highlight-current-row highlight-hover-row resizable stripe :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }">
                      <vxe-table-column type="index" title="NO." width="50"></vxe-table-column>
                      <vxe-table-column field="qcruletype" title="规则大类" width="120" header-align="center" :edit-render="{ type: 'default' }">
                          <template v-slot="{ row }">
                              <el-select v-model="row.qcruletype">
                                  <el-option v-for="item in westgardOption" :key="item.value" :label="item.label" :value="item.value">{{ item.label }}</el-option>
                              </el-select>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="qcrule" title="Westgard规则(双击修改)" width="400" header-align="center"></vxe-table-column>
                      <vxe-table-column field="begindt" title="启用日期" width="150" header-align="center" align="center" :formatter="['toDateString', 'yyyy-MM-dd']">
                          <template v-slot="{ row }">
                              <el-date-picker v-model="row.begindt" type="date" placeholder="选择日期" style="width: 100%"></el-date-picker>
                          </template>
                      </vxe-table-column>

                      <vxe-table-column field="stopdt" title="结束日期" width="150" header-align="center" align="center" :formatter="['toDateString', 'yyyy-MM-dd']">
                          <template v-slot="{ row }">
                              <el-date-picker v-model="row.stopdt" type="date" placeholder="选择日期" style="width: 100%"></el-date-picker>
                          </template>
                      </vxe-table-column>
                  </vxe-table>
              </div>
              <template v-slot:fix>
                  <div style="height:100%;width:100%">
                      <div class="tabtop">
                          <div class="tab-title">质控规则仪器选项</div>
                      </div>
                      <div class="datacenter">
                          <el-form ref="form" :model="sizeForm" :disabled="powRet==0?true:false">
                              <table border="0" style="width:100%">
                                  <!--内容-->
                                  <tr class="scroll_content" v-for="(sitems, sindex) in insoption" :key="sindex">
                                      <td>
                                          <div v-if="sitems.valuetype == 1">
                                              <!--1 checkbox-->
                                              <table border="0">
                                                  <!-- <tr @mouseenter="mouseenter(sitems.optioncode)" @mouseleave="mouseleave(sitems.optioncode)" :class="{
                          mouseactive: iindex === sitems.optioncode,
                        }"> -->
                                                  <tr>
                                                      <td align="left" style="width:95px;text-align:center">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <b>{{ sitems.optionseq }}</b>
                                                          </div>
                                                          <div v-else>
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                      </td>
                                                      <td style="width:20px">
                                                          <el-checkbox v-model="sitems.optionvalue" :disabled="sitems.optionflag == 0" true-label="1" false-label="0" @change="
                              SaveSetting(
                                sitems.sysno,
                                sitems.optioncode,
                                sitems.optionvalue,
                                sitems
                              )
                            "></el-checkbox>
                                                      </td>
                                                      <td @click="
                            chkcheckbox(
                              sitems.sysno,
                              sitems.optioncode,
                              sitems.optionvalue,
                              sitems
                            )
                          ">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <!-- <el-tooltip :disabled="
                                sitems.description == sitems.optionname
                              " :content="sitems.description" placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  <b>{{ sitems.optionname }}</b>
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else>
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                      </td>
                                                      <td align="right">&nbsp;&nbsp;&nbsp;<i class="el-icon-chat-dot-round" style="color:green;font-size:18px" @click="iconclick(sitems.description)" v-if="
                                sitems.description != sitems.optionname
                              "></i></td>
                                                  </tr>
                                              </table>
                                          </div>
                                          <div v-else-if="sitems.valuetype == 'color'">
                                              <!--color-->
                                              <table border="0">
                                                  <!-- <tr @mouseenter="mouseenter(sitems.optioncode)" @mouseleave="mouseleave(sitems.optioncode)" :class="{
                          mouseactive: iindex === sitems.optioncode,
                        }"> -->
                                                  <tr>
                                                      <td align="left" style="width:95px;text-align:center">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <b>{{ sitems.optionseq }}</b>
                                                          </div>
                                                          <div v-else>
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                      </td>
                                                      <td style="width:20px">
                                                          <el-color-picker size="mini" v-model="sitems.optionvalue" :disabled="sitems.optionflag == 0" @change="
                              SaveSetting(
                                sitems.sysno,
                                sitems.optioncode,
                                sitems.optionvalue
                              )
                            "></el-color-picker>
                                                      </td>
                                                      <td style="vertical-align:middle;">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <!-- <el-tooltip :disabled="
                                sitems.description == sitems.optionname
                              " :content="sitems.description" placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  <b>{{ sitems.optionname }}</b>
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else>
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                      </td>
                                                      <td align="right">&nbsp;&nbsp;&nbsp;<i class="el-icon-chat-dot-round" style="color:green;font-size:18px" @click="iconclick(sitems.description)" v-if="
                                sitems.description != sitems.optionname
                              "></i></td>
                                                  </tr>
                                              </table>
                                          </div>
                                          <div v-else>
                                              <table border="0">
                                                  <!-- <tr @mouseenter="mouseenter(sitems.optioncode)" @mouseleave="mouseleave(sitems.optioncode)" :class="{
                          mouseactive: iindex === sitems.optioncode,
                        }"> -->
                                                  <tr>
                                                      <td align="center" style="width:95px;text-align:center;">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              <!--禁止-->
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <!--加粗-->
                                                              <b>{{ sitems.optionseq }}</b>
                                                          </div>
                                                          <div v-else>
                                                              <!--正常-->
                                                              {{ sitems.optionseq }}
                                                          </div>
                                                      </td>
                                                      <td style="width:20px"></td>
                                                      <td style="text-align:left">
                                                          <div v-if="sitems.optionflag == 0" style="color:#BABFCC">
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                                  &nbsp;&nbsp;&nbsp;
                                                                  <i class="el-icon-chat-dot-round" style="color:green;font-size:18px" @click="iconclick(sitems.description)" v-if="
                                sitems.description != sitems.optionname
                              "></i>
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else-if="sitems.optionflag == 2" style="color:red">
                                                              <!-- <el-tooltip :disabled="
                                sitems.description == sitems.optionname
                              " :content="sitems.description" placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  <b>{{ sitems.optionname }}</b>
                                                                  &nbsp;&nbsp;&nbsp;
                                                                  <i class="el-icon-chat-dot-round" style="color:green;font-size:18px" @click="iconclick(sitems.description)" v-if="
                                sitems.description != sitems.optionname
                              "></i>
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                          <div v-else>
                                                              <!-- <el-tooltip :content="sitems.description" :disabled="
                                sitems.description == sitems.optionname
                              " placement="top-start" effect="dark"> -->
                                                              <div>
                                                                  {{ sitems.optionname }}
                                                                  &nbsp;&nbsp;&nbsp;
                                                                  <i class="el-icon-chat-dot-round" style="color:green;font-size:18px" @click="iconclick(sitems.description)" v-if="
                                sitems.description != sitems.optionname
                              "></i>
                                                              </div>
                                                              <!-- </el-tooltip> -->
                                                          </div>
                                                      </td>
                                                  </tr>
                                                  <tr>
                                                      <td></td>
                                                      <td></td>
                                                      <td>
                                                          <div v-if="sitems.valuetype == 2">
                                                              <!--2-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-input v-model="sitems.optionvalue" @input="
                                      btnactivetest(
                                        sitems.optioncode,
                                        sitems.optionvalue
                                      )
                                    " :disabled="sitems.optionflag == 0">
                                                                          </el-input>
                                                                      </td>
                                                                      <td>
                                                                          <el-button :class="sitems.type_en" :disabled="sitems.optionflag == 0" :type="
                                      SitemsOptioncode.indexOf(
                                        sitems.optioncode
                                      ) > -1
                                        ? 'danger'
                                        : ''
                                    " :id="'btnactive_' + sitems.optioncode" @click.native="
                                      SaveSetting(
                                        sitems.sysno,
                                        sitems.optioncode,
                                        sitems.optionvalue
                                      )
                                    ">保存</el-button>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 3">
                                                              <!--3-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-select v-model="sitems.optionvalue" filterable @change="
                                      SaveSetting(
                                        sitems.sysno,
                                        sitems.optioncode,
                                        sitems.optionvalue
                                      )
                                    " :disabled="sitems.optionflag == 0" style="width:250px">
                                                                              <el-option v-for="item in sitems.valuelist.split(
                                        '|'
                                      )" :key="item.split(' ')[0]" :label="
                                        item.substring(item.indexOf(' '))
                                      " :value="item.split(' ')[0]">
                                                                              </el-option>
                                                                          </el-select>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 4">
                                                              <!--4-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-input v-model="sitems.optionvalue" :disabled="sitems.optionflag == 0" ref="refMutipleSelect" :key="1" placeholder="列表多选双击开窗" readonly @dblclick.native="
                                      DialogMutipleSelect(
                                        sitems.valuelist,
                                        sitems.optionvalue,
                                        sitems.optionname,
                                        sitems.optioncode
                                      )
                                    ">
                                                                          </el-input>
                                                                      </td>
                                                                      <td v-show="false">
                                                                          <el-input :id="
                                      'listmutipleid1_' + sitems.optioncode
                                    " v-model="sitems.sysno"></el-input>
                                                                          <el-input :id="
                                      'listmutipleid2_' + sitems.optioncode
                                    " v-model="sitems.optioncode"></el-input>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 5">
                                                              <!--5-->
                                                              <!--sql单选-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <rm_ddl_SqlSingle :sql="sitems.valuelist" :key="sitems.optioncode+'_'+rptunitval" :keyid="rptunitval" :optionflag="sitems.optionflag" v-model="sitems.optionvalue" ref="refSqlSingle" width="158px" @change="SaveSetting(sitems.sysno,sitems.optioncode,$event)">
                                                                          </rm_ddl_SqlSingle>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 6">
                                                              <!--6 SQL多选-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-input v-model="sitems.optionvalue" ref="refSql" :disabled="sitems.optionflag == 0" :key="sitems.optioncode" placeholder="SQL多选双击开窗" readonly @dblclick.native="DialogSql(sitems.valuelist,sitems.optionvalue,sitems.optionname,sitems.optioncode)">
                                                                          </el-input>
                                                                      </td>
                                                                      <td v-show="false">
                                                                          <el-input :id="'sqlmutipleid1_' + sitems.optioncode" v-model="sitems.sysno">
                                                                          </el-input>
                                                                          <el-input :id="'sqlmutipleid2_' + sitems.optioncode" v-model="sitems.optioncode">
                                                                          </el-input>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 7">
                                                              <!--7-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-input v-model="sitems.optionvalue" ref="refSort" :disabled="sitems.optionflag == 0" :key="1" placeholder="排序双击开窗" readonly @dblclick.native="
                                      DialogSort(
                                        sitems.valuelist,
                                        sitems.optionvalue,
                                        sitems.optionname,
                                        sitems.optioncode
                                      )
                                    ">
                                                                          </el-input>
                                                                      </td>
                                                                      <td v-show="false">
                                                                          <el-input :id="
                                      'sortmutipleid1_' + sitems.optioncode
                                    " v-model="sitems.sysno"></el-input>
                                                                          <el-input :id="
                                      'sortmutipleid2_' + sitems.optioncode
                                    " v-model="sitems.optioncode"></el-input>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 'printer'">
                                                              <!--printer-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <el-select v-model="sitems.optionvalue" filterable @change="
                                      SaveSetting(
                                        sitems.sysno,
                                        sitems.optioncode,
                                        sitems.optionvalue
                                      )
                                    " :disabled="sitems.optionflag == 0" style="width:158px">
                                                                              <el-option v-for="pitem in printers" :key="pitem" :value="pitem" :label="pitem">
                                                                              </el-option>
                                                                          </el-select>
                                                                      </td>
                                                                      <td>
                                                                          <rm-print-comm :prnt_type="sitems.valuelist" :prnt_name="sitems.optionvalue" @save="PrintSetingSave($event, sitems)"></rm-print-comm>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <div v-else-if="sitems.valuetype == 'design'">
                                                              <!--design-->
                                                              <table>
                                                                  <tr>
                                                                      <td>
                                                                          <rm_ddl_Design :sqlval="sitems.valuelist" :key="sitems.optionseq" :optionflag="sitems.optionflag" ref="refDesign" @change="
                                      SaveSetting(
                                        sitems.sysno,
                                        sitems.optioncode,
                                        $event
                                      )
                                    " :value="sitems.optionvalue" width="158px">
                                                                          </rm_ddl_Design>
                                                                      </td>

                                                                      <td></td>
                                                                      <td>
                                                                          <el-button :class="sitems.type_en" :disabled="sitems.optionflag == 0" :id="'btnactive_' + sitems.optioncode" @click.native="
                                      JustifyRptStyle(
                                        sitems.sysno,
                                        sitems.optioncode,
                                        sitems.optionvalue,
                                        sitems.valuelist,
                                        sitems.defaultvalue
                                      )
                                    ">调整样式</el-button>
                                                                      </td>
                                                                      <td>
                                                                          <rm-print-comm :prnt_type="
                                      sitems.valuelist == 'BARCODE.01'
                                        ? 'barcode'
                                        : sitems.valuelist
                                    "></rm-print-comm>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <!--upimg-->
                                                          <div v-if="sitems.valuetype == 'upimg'">
                                                              <table>
                                                                  <tr>
                                                                      <td></td>
                                                                      <td>
                                                                          <rm-imgupload :data="sitems" :key="imgkey" :SQLKEY="SQLKEY" :OptionClass="OptionClass" :hospcode="hospitalcode" :objectid="rptunitval" :macaddress="macadress" @change="uploadimg"></rm-imgupload>
                                                                      </td>
                                                                  </tr>
                                                              </table>
                                                          </div>
                                                          <!--rptunit-->
                                                          <div v-if="sitems.valuetype == 'rptunit'">
                                                              <rm-ddl-rptunit prgno="MNG133" @change="SaveSetting(sitems.sysno,sitems.optioncode,$event)" v-model="sitems.optionvalue" width="200px" v-el-drag-dialog :appendtobody="true" :clearable="true" :close-on-click-modal="false" defaultflag="0"></rm-ddl-rptunit>
                                                          </div>
                                                          <!--instr-->
                                                          <div v-if="sitems.valuetype == 'instr'">
                                                              <rm-ddl-instrument @change="SaveSetting(sitems.sysno,sitems.optioncode,$event)" v-model="sitems.optionvalue" width="200px" v-el-drag-dialog :appendtobody="true" :close-on-click-modal="false" :clearable="true" defaultflag="0"></rm-ddl-instrument>
                                                          </div>
                                                      </td>
                                                  </tr>
                                              </table>
                                          </div>
                                      </td>
                                  </tr>
                              </table>
                          </el-form>
                      </div>
                  </div>
              </template>
          </rm-layout-right>
      </div>
      <el-dialog width="600px" top="10px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="选择Westgard质控规则" :visible.sync="qcruleDialogVisible">
          <vxe-table ref="xTable2" height="480" width="100%" :loading="loading" :select-config="{ reserve: true }" :data.sync="tableData2" border size="mini" :row-class-name="rowClassName" :keyboard-config="keyConfig" :mouse-config="{ selected: true }" show-header-overflow highlight-current-row highlight-hover-row resizable stripe :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true }">
              <vxe-table-column type="selection" width="50" align="center"></vxe-table-column>
              <vxe-table-column field="qcrule" title="质控规则" width="100" align="center"></vxe-table-column>
              <vxe-table-column field="ruleText" title="规则内容" width="400" header-align="center"></vxe-table-column>
          </vxe-table>
          <span slot="footer" class="dialog-footer">
              <el-button style="margin: 0px 10px 0px 5px" icon="el-icon-success" @click="ruleOk()">确定</el-button>
              <el-button style="margin: 0px 10px 0px 5px" icon="el-icon-close" @click="ruleClose()">退出</el-button>
          </span>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils"; //引入工具类
import axios from "axios";
import pconst from "../../../common/printconst.js";
export default {
  name: "LIS513",
  data() {
      return {
          loading: false,
          qcruleDialogVisible: false,
          instrId: 0,
          tableData1: [],
          tableData2: [],
          insoption: [],
          iindex: 0,
          powRet: 0,
          sizeForm: {},
          keyConfig: {
              isArrow: true,
              isDel: true,
              isTab: true,
              isEdit: true,
              editMethod: ({ seq, row, rowIndex, column, columnIndex, cell }) => {},
          },

          westgardOption: [
              { label: "Westgard", value: 1 },
              { label: "绝对值", value: 2 },
              { label: "百分比", value: 3 },
              { label: "定性质控", value: 4 },
          ],
      };
  },

  //html加载完成之前，执行。执行顺序：父组件-子组件
  created() {},
  //.html加载完成后执行。执行顺序：子组件-父组件
  mounted() {},
  updated() {},
  watch: {
      instrId(val) {
          this.initialList();
          this.InitPageDate();
          this.getInstrOptionPower();
      },
  },
  methods: {
      iconclick(infomation) {
          this.$alert(infomation, "信息", { dangerouslyUseHTMLString: true });
      },
      //选项保存
      SaveSetting(sysno, optioncode, optionvalue) {
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "SaveSetting",
                      sysno: sysno,
                      optioncode: optioncode,
                      optionvalue: optionvalue,
                      instrid: this.instrId,
                  },
              })
              .then((res) => {
                  if (res.errcode != "1") {
                      this.$message({
                          message: "保存设置失败！" + res.errmsg,
                          type: "error",
                          showClose: true,
                      });
                  } else {
                      this.$message({
                          message: "保存设置成功！",
                          type: "success",
                          duration: "1000",
                          showClose: true,
                      });
                  }
                  this.InitPageDate();
              })
              .catch((e) => {
                  console.log("error", e);
              });
      },
      initialList() {
          //主表查询
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "query",
                      instrid: this.instrId,
                      ruleType: "All",
                  },
              })
              .then((res) => {
                  // console.log("🤣 ~ res", res);
                  this.tableData1 = res.Data;
                  this.loading = false;
              })
              .catch((e) => {
                  this.loading = false;
                  console.log("error", e);
              });
      },
      InitPageDate() {
          //页面查询
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "InitPageDate",
                      instrid: this.instrId,
                  },
              })
              .then((res) => {
                  this.insoption = res[0];
                  // console.log("🤣 ~ this.insoption", this.insoption);
                  // console.log("🤣 ~ res", res);
                  // this.nArray = res; // JSON.parse(res);
                  // console.log("🤣 ~ this.nArray", this.nArray);
              })
              .catch((e) => {
                  // console.log("error-InitPageDate", e);
              });
      },
      getInstrOptionPower() {
          this.powRet = 0;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "getInstrOptionPower",
                      instrId: this.instrId,
                  },
              })
              .then((res) => {
                  // console.log("🤣 ~ re1111s", res);
                  this.powRet = res;
              })
              .catch((error) => {
                  this.$alert(error, "错误");
              });
      },
      QSecOption() {
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "QSecOption",
                      txtsearch: this.txtsearch,
                      macadress: this.macadress,
                      sqlkey: this.SQLKEY,
                      optionclass: this.OptionClass,
                      rptunitid: this.rptunitval,
                      hospitalcode: this.hospitalcode,
                  },
              })
              .then((res) => {
                  if (this.queryflag == false) {
                      this.optionkindOptions.push({
                          actionid: "查询专用标记",
                          actionname: "查询",
                      });
                      this.queryflag = true;
                  }
                  //this.checkOne = "查询专用标记";
                  this.actionid = "查询专用标记";
                  this.nArray = res;
              })
              .catch((e) => {
                  console.log("error-QSecOption", e);
              });
      },
      //打开质控规则选择窗口
      openRule({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, cell }) {
          if (row) this.$refs.xTable1.setCurrentRow(row);
          else this.$refs.xTable1.setCurrentRow(null);
          var rule = row.qcrule;
          //console.log("🤣 ~ rule", rule);
          var rulearr = rule.split(",");
          this.qcruleDialogVisible = true;
          this.$tool
              .request({
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "getQcrule",
                  },
              })
              .then((response) => {
                  this.tableData2 = response.Data;
                  if (rulearr.length > 0) {
                      for (let i = 0; i < rulearr.length; i++) {
                          var selrow = this.tableData2.filter((item) => item.qcrule == rulearr[i]);
                          if (selrow.length > 0) {
                              this.$refs.xTable2.setSelection(selrow[0], true);
                          }
                      }
                  }
              });
      },

      //弹窗选择质控规则后 确认按钮
      ruleOk() {
          var selectRows = this.$refs.xTable2.getSelectRecords();
          if (selectRows) {
              var qcrule = "";
              for (let index in selectRows) {
                  qcrule += "," + selectRows[index].qcrule;
              }
              if (qcrule.trim().length > 0) {
                  qcrule = qcrule.substring(1);
              } else {
                  qcrule = "";
              }
          } else {
              return;
          }
          var currentRow = this.$refs.xTable1.getCurrentRow();
          currentRow.qcrule = qcrule;
          this.qcruleDialogVisible = false;
      },

      //弹窗选择质控规则后 关闭按钮
      ruleClose() {
          this.qcruleDialogVisible = false;
      },

      //停止日期小于小当前日期的行 ，底色变红色
      rowClassName({ row, rowIndex }) {
          var today = new Date();
          if (row.stopdt) {
              if (row.stopdt < today) {
                  return "rm-alert";
              }
          }
      },

      //切换仪器时刷新界面
      labinstrumentchange(id, name) {
          this.instrId = id;
          this.initialList();
      },

      BtnAdd() {
          if (this.instrId) {
              var row = {};
              row.qcruletype = 1;
              row.begindt = XEUtils.toStringDate(XEUtils.toDateString(new Date(), "yyyy-MM-dd"));
              row.qcrule = "1_3S,2_2S,R4S,4_1S,10X";
              this.insertRowAtLast(this.$refs.xTable1, row);
          } else {
              this.$alert("请先选择仪器!", "提示");
          }
      },

      BtnSave() {
          if (this.instrId == 0) {
              this.$message("请选择仪器");
              return false;
          }
          //校验 数据
          var record = this.$refs.xTable1.tableData;
          for (let i = 0, len = record.length; i < len; i++) {
              let msg;
              msg = this.valid(record[i].qcruletype, "第" + (i + 1) + "行 规则大类 必须填写！");
              if (msg) return msg;
              msg = this.valid(record[i].begindt, "第" + (i + 1) + "行 启用日期 必须填写！");
              if (msg) return msg;
          }
          let xTable1data = this.$refs.xTable1.getRecordset();
          this.getDataByAjax(
              {
                  url: "LIS/LIS5/LIS513",
                  method: "post",
                  data: {
                      action: "save",
                      instrId: this.instrId,
                      urec: xTable1data,
                      ruleType: "All",
                  },
              },
              "操作成功！",
              "保存失败！",
              (data) => {
                  //okFunction
                  this.initialList();
              },
              (data) => {
                  //errFunction
              }
          );
      },

      BtnDel() {
          this.deleteRow(this.$refs.xTable1);
      },

      ///////////////////////////////////工具函数 /////////////////////////////////////////
      getDataByAjax(
          request,
          okMsg,
          errMsg,
          okFunction, // 取得数据后的回调函数
          errFunction // 获取数据失败后回调函数
      ) {
          this.$tool.request(request).then((response) => {
              if (response.errcode == "1") {
                  if (XEUtils.isString(okMsg)) {
                      if (XEUtils.getSize(XEUtils.trim(okMsg)) > 0) {
                          this.$message({
                              message: okMsg,
                              type: "success",
                          });
                      }
                  }
                  if (typeof okFunction == "function") okFunction(response.Data);
              } else {
                  this.$message({
                      dangerouslyUseHTMLString: true,
                      message: errMsg + "<br><br>详细信息：" + response.errmsg,
                      type: "warning",
                  });
                  if (typeof errFunction == "function") errFunction(response.Data);
              }
          });
      },

      insertRowAtLast(xtable, row) {
          xtable.insertAt(row, -1); //在最后添加一行
          var curow = xtable.getTableData().fullData[xtable.getTableData().fullData.length - 1]; //获取 新加的行对象 row 数据集合
          xtable.setCurrentRow(curow); //高亮显示行
          this.$nextTick(() => {
              xtable.scrollToRow(curow); //待数据加载完成后，延迟 滚动 到行
          });
      },

      //自动加载表格的第一行，并执行回调函数
      loadFirstRow(xTable, func) {
          this.$nextTick(() => {
              // 加载第一行
              var selectrow = xTable.getData(0);
              if (selectrow) {
                  xTable.setCurrentRow(selectrow); //高亮行
                  xTable.scrollToRow(selectrow); //滚动到行
                  if (typeof func == "function") func(selectrow);
              } else {
                  xTable.setCurrentRow(null); //这个不会自动清空
              }
          });
      },

      //自制必填校验函数，以后待扩展
      valid(obj, message) {
          if (XEUtils.isUndefined(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isNull(obj)) {
              return this.$message({
                  message: message,
                  type: "warning",
              });
          }
          if (XEUtils.isString(obj)) {
              if (!XEUtils.getSize(obj) > 0) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
          if (XEUtils.isDate(obj)) {
              if (obj < XEUtils.toStringDate("2000-01-01")) {
                  return this.$message({
                      message: message,
                      type: "warning",
                  });
              }
          }
      },

      //删除表格行工具//TODO 连续 点删除按钮会有失去焦点的问题待解决
      deleteRow(xTable) {
          var delrow = xTable.getCurrentRow();
          if (delrow) {
              this.DelIndex = xTable.getRowIndex(delrow);
              xTable.remove(delrow);
              if (this._this.DelIndex > -1 && xTable.tableData.length > 0) {
                  if (xTable.getTableData().fullData.length > this.DelIndex) this.DelIndex = this.DelIndex;
                  elsethis.DelIndex = this.DelIndex - 1;
                  var selectrow = xTable.getTableData().fullData[this._this.DelIndex];
                  this.$nextTick(() => {
                      xTable.setCurrentRow(selectrow);
                  });
              } else {
                  var nowdata = xTable.getTableData().fullData.filter((item) => {
                      return item._XID < delrow._XID;
                  });
                  if (nowdata.length > 0) {
                      var selectrow = nowdata[nowdata.length - 1];
                      this.$nextTick(() => {
                          xTable.setCurrentRow(selectrow);
                      });
                  }
              }
          }
      },

      stddevp(numbers) {
          var mean = 0;
          var sum = 0;
          var avgValue, sdValue, cvValue;
          for (var i = 0; i < numbers.length; i++) {
              sum += Number(numbers[i]);
          }
          mean = sum / numbers.length;
          avgValue = mean;

          sum = 0;
          for (var i = 0; i < numbers.length; i++) {
              sum += Math.pow(numbers[i] - mean, 2);
          }
          sdValue = Math.sqrt(sum / numbers.length);

          if (avgValue != 0) {
              cvValue = (sdValue * 100) / avgValue;
          } else {
              cvValue = null;
          }
          return {
              avgValue: XEUtils.toFixedString(mean, 2),
              sdValue: XEUtils.toFixedString(sdValue, 2),
              cvValue: XEUtils.toFixedString(cvValue, 2),
          };
      },
      //关闭按钮
      BtnExc() {
          let index = this.$parent.$refs.itemtags.tagsList.findIndex((m) => m.name == "LIS510");
          this.$parent.$refs.itemtags.tagsList.splice(index, 1);
          this.$router.go(-1);
      },
  },
  chkcheckbox(sysno, optioncode, optionvalue, sitems) {
      //sitems包含了这条数据的所有列
      let arrval = [null, "", "0"];
      if (arrval.indexOf(optionvalue.trim()) > -1) {
          optionvalue = "0";
      }
      let chkvalue = optionvalue == "0" ? "1" : "0";
      this.SaveSetting(sysno, optioncode, chkvalue, sitems);
  },
  mouseenter(sindex) {
      this.iindex = sindex;
  },
  mouseleave(sindex) {
      this.iindex = -1;
  },
  beforeRouteEnter(to, from, next) {
      next((vm) => {
          let that = vm;
          let altArr = [];
          document.onkeydown = function (e) {
              let key = window.event.keyCode;
              // console.log("key=", key);
              //*组合按键
              if (altArr.length > 0) {
                  //65到90 a到z（A到Z）
                  // //*Alt + C 清除
                  // if (key == 67) {
                  //     this.BtnExc();
                  // }
                  //*Alt + E 退出
                  if (key == 69) {
                      that.BtnExc();
                  }
              } else {
                  if (key == 119) {
                      //F8
                      that.initialList();
                  } else if (key == 113) {
                      //F2
                      var e = [];
                      e.shiftKey = false;
                      that.BtnAdd(e);
                  } else if (key == 114) {
                      //F3
                      that.BtnDel();
                  } else if (key == 117) {
                      //F6
                      that.BtnSave();
                  } else if (key == 18) {
                      // console.log("按下'ALT'");
                      //按下了alt
                      altArr.push(key);
                  }
              }
          };
          document.onkeyup = function (e) {
              let key = window.event.keyCode;
              if (key == 18) {
                  altArr = [];
              }
          };
      });
  },
};
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  height: 30px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  text-align: left;
}
.pagebottom {
  width: 100%;
  height: 40px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: left;
  position: absolute;
  bottom: 0px;
  font-size: 12px;
  border: solid 1px #ccc;
}
.pagecenter {
  position: absolute;
  top: 35px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}
.middle-center {
  position: absolute;
  height: 100%;
  right: 485px;
  left: 0;
}
.scroll_title {
  padding: 0px 0px 0px 0px;
  color: #333333;
  background-color: #d6d9da;
  font-size: 14px;
  font-weight: bold;
}
.scroll_content {
  line-height: 30px;
  color: #5e6267;
  font-size: 15px;
  text-decoration: none;
  -webkit-transition: color 0.3s;
  transition: color 0.3s;
  padding-left: 50px;
}

.middle-right {
  position: absolute;
  top: 0;
  bottom: 2px;
  overflow: visible;
  width: 480px;
  right: 0px;
}
table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
}
.mouseactive {
  color: cornflowerblue;
  cursor: pointer;
}
.datacenter {
  position: absolute;
  top: 30px;
  width: 100%;
  left: 0;
  bottom: 5px;
}
.tab-title {
  margin: 0;
  font-size: 13px;
  /* margin: 0 1px 0 3px; */
  padding: 0 1px 0 3px;
  font-weight: 600;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
.tabtop {
  width: 100%;
  height: 26px;
  line-height: 26px;
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
  border-right: 1px solid #ccc;
  white-space: nowrap;
}
hr.style18 {
  height: 30px;
  border-style: solid;
  border-color: #8c8b8b;
  border-width: 1px 0 0 0;
  border-radius: 20px;
}
hr.style18:before {
  display: block;
  content: "";
  height: 30px;
  margin-top: -31px;
  border-style: solid;
  border-color: #8c8b8b;
  border-width: 0 0 1px 0;
  border-radius: 20px;
}
</style>


